//户籍地
function onHjqcSuoActionRendererHj(e) {
    var record = e.value;
    if (record != null) {
        var arr = record.split("@");
        var sq = arr[0];
        var level = arr[1];
    }
    var s = "";
    if (sq == "未申请" && level == '03') {
        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="apply()"  >&nbsp;&nbsp;申请&nbsp;&nbsp;</a>&nbsp';
    }
    if ((sq == "审批失败" || sq == "重新发起申请") && level == '03') {
        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="apply()"  >&nbsp;&nbsp;重新发起申请&nbsp;&nbsp;</a>&nbsp';
    }
    if (sq != "未申请") {
        s += '&nbsp;<a class="mini-button mini-button-success"  onclick="details()"  >&nbsp;&nbsp;详情&nbsp;&nbsp;</a>&nbsp';
    }
    s += '&nbsp;<a class="mini-button mini-button-info"  onclick="toViewHjqc()"  >&nbsp;&nbsp;查看&nbsp;&nbsp;</a>&nbsp';
    return s;
}

//居住地
function onHjqcSuoActionRendererJz(e) {
    var record1 = e.value;
    var dateJc;
    if (record1 != null) {
        var arr = record1.split("@");
        var record = arr[0];
        var level = arr[1];
        //双列管解除时间
        dateJc = arr[2];
    }
    var s = "";
    if (record == "等待审批" && level == '03') {
        s += '&nbsp;<a class="mini-button mini-button-warning"  onclick="approval()"  >&nbsp;&nbsp;审批&nbsp;&nbsp;</a>&nbsp';
    } else if (record == "审批通过" && level == '03') {
        s += '&nbsp;<a class="mini-button mini-button-warning"   onclick="removeSlg()"  >&nbsp;&nbsp;移除&nbsp;&nbsp;</a>&nbsp';
    }
    s += '&nbsp;<a class="mini-button mini-button-info"  onclick="toViewHjqc()"  >&nbsp;&nbsp;查看&nbsp;&nbsp;</a>&nbsp';
    s += '&nbsp;<a class="mini-button mini-button-success"  onclick="details()"  >&nbsp;&nbsp;详情&nbsp;&nbsp;</a>&nbsp';
    return s;
}

// 申请
function apply() {
    var row = grid.getSelected();
    if (row) {
        $.ajax({
            url: "/azbj/inmates/getHasDate?priNum=" + row.prinum,
            type: "GET",
            async: false,
            success: function (result) {
                if (result == "no") {
                    mini.alert("请补录该服刑人员的刑期起止日");
                } else {
                    /*if (row.shenstate != "未申请" && row.shenstate != "审批失败") {
                        mini.alert("该服刑人员已申请！处于" + row.shenstate + "状态");
                    } else {*/
                        //根据row.priNum查找居住地是否为空，如果不为空则申请双列管
                        $.ajax({
                            url: "/azbj/slg/checkPlaceVillexist?priNum=" + row.prinum,
                            type: "get",
                            cache: false,
                            async: false,
                            success: function (success) {
                                if (success.code == 1) {
                                    if ((success.data.placepro != null && success.data.placepro != "" && success.data.placepro != "undefined") &&
                                        (success.data.placecity != null && success.data.placecity != "" && success.data.placecity != "undefined") &&
                                        (success.data.placecou != null && success.data.placecou != "" && success.data.placecou != "undefined") &&
                                        (success.data.placevill != null && success.data.placevill != "" && success.data.placevill != "undefined")) {
                                        mini.open({
                                            //targetWindow: window,
                                            url: "/azbjgl/slg/toapply/view?priNum=" + row.prinum + "&id=" + row.id + "&sex=" + row.sex + "&pname=" + row.pname + "&villid=" + row.placevill,
                                            title: "申请双列管:", width: 700, height: 400,
                                            allowResize: false,
                                            onload: function () {

                                            },
                                            ondestroy: function (action) {
                                                if (action == "ok"){
                                                    grid.reload();
                                                }else{
                                                    $.ajax({
                                                        url: "/upload/downloadAppendixFile/deleteById?1=1&id=" + row.id + "&priNum=" + row.prinum + "&taskId=7",
                                                        type: 'get',
                                                        success: function (success) {
                                                        }
                                                    });
                                                    $.ajax({
                                                        url: "/upload/downloadAppendixFile/deleteById?1=1&id=" + row.id + "&priNum=" + row.prinum + "&taskId=8",
                                                        type: 'get',
                                                        success: function (success) {
                                                        }
                                                    });
                                                }
                                                grid.reload();
                                            }
                                        });
                                    } else {
                                        mini.alert("居住地址为空无法申请双列管!")
                                    }
                                } else {
                                    mini.alert("居住地址为空无法申请双列管!")
                                }
                            }
                        })
                    }
                }

        })
    } else {
        mini.alert("请选择一条记录");
    }
}

// 审批
function approval() {
    var row = grid.getSelected();
    if (row) {
        if (row.state != "2") {
            mini.alert("该服刑人员已完成审批！现处于" + row.shenstate + "状态");
        } else {
            mini.open({
                //targetWindow: window,
                url: "/azbjgl/slg/approval/view?priNum=" + row.prinum + "&id=" + row.id,
                title: "审批双列管", width: 700, height: 400,
                allowResize: false,
                onload: function () {

                },
                ondestroy: function (action) {
                    grid.reload();
                }
            });
        }
    } else {
        mini.alert("请选择一条记录");
    }
}

function details() {
    var row = grid.getSelected();
    if (row) {
        mini.open({
            //targetWindow: window,
            url: "/azbjgl/slg/details/view?priNum=" + row.prinum + "&id=" + row.id,
            title: "双列管详情", width: 600, height: 550,
            allowResize: false,
            onload: function () {

            },
            ondestroy: function (action) {
                grid.reload();
            }
        });
    } else {
        mini.alert("请选择一条记录");
    }
}

function removeSlg() {
    var row = grid.getSelected();
    if (row) {
        $.ajax({
            url: "/azbj/inmates/getHasDate?priNum=" + row.prinum,
            type: "GET",
            async: false,
            success: function (result) {
                if (result == "no") {
                    mini.alert("请补录该服刑人员的刑期起止日");

                } else {
                    var url = "/azbj/azbjgl/slginforemove";
                    $.ajax({
                        url: url,
                        type: 'POST',
                        cache: false,
                        async: false,
                        data: {priNum: row.prinum},
                        success: function (result) {
                            if (result.code == 1) {
                                mini.alert("已移除双列管");
                            } else {
                                if (row.state != "1") {
                                    mini.alert("该服刑人员未审批通过，无法移除双列管");
                                } else {
                                    mini.confirm("确定移除双列管？", "确定?"
                                        , function (action) {
                                            if (action == 'ok') {
                                                mini.open({
                                                    //targetWindow: window,
                                                    url: "/azbjgl/slg/removeSlg/view?priNum=" + row.prinum + "&id=" + row.id,
                                                    title: "移除双列管", width: 600, height: 400,
                                                    allowResize: false,
                                                    onload: function () {

                                                    },
                                                    ondestroy: function (action) {
                                                        grid.reload();
                                                    }
                                                });
                                            }
                                        });
                                }
                            }
                        }, error: function () {
                            mini.alert("操作失败!");
                        }
                    });
                }
            }
        })


    } else {
        mini.alert("请选择一条记录");
    }
}

//查看
function toViewHjqc() {
    var row = grid.getSelected();
    mini.open({
        url: "/azbj/bjdxInfo/hjqc/toViewTabs/view?priNum=" + row.prinum,
        title: "查看",
        width: "60%",
        height: "80%",
        allowDrag: true,
        allowResize: false,
        showCloseButton: true,
        onload: function () {
        },
        ondestroy: function (action) {
            grid.reload();
        }
    });
}